package com.gz.web.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 如果在一个类上标注了ControllerAdvice,那么就是处理全局异常处理类
 */

@ControllerAdvice
public class MyGlobalException {
    //全局异常就是不管在哪个Handler抛出的异常，都可以捕获

    @ExceptionHandler({ArithmeticException.class,NumberFormatException.class,AgeException.class })
    public String globalException(Exception ex, HttpServletRequest request) {
        System.out.println("全局异常处理-"+ex.getMessage());
        request.setAttribute("reason", ex.getMessage());
        return "exception_mes";
    };
}
